//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:20-4-14
// @Time:下午1:56
//

#include "BaseBusiness.h"
#include <handy/handy.h>
#include "GeeJoan/NetWorkPackage.pb.h"
#include "GeeJoan/ErrorModule.pb.h"

using namespace handy;
using namespace GeeJoan::Protocol::NetWork;
using namespace GeeJoan::Protocol::Error;

int BaseBusiness::call200(EventContext *context, std::string &body)
{
    NetWorkPackageRespose respose;
    respose.set_taskid( context->taskid );
    respose.set_type_sub( context->sub_type );
    respose.set_type_m((NetWorkPackageModel) context->mod_type );
    respose.set_code( 200 );
    respose.set_body( body );
    context->con->send( respose.SerializeAsString());
    return 0;
}


int BaseBusiness::call200(EventContext *context, void *data, int len)
{
    NetWorkPackageRespose respose;
    respose.set_taskid( context->taskid );
    respose.set_type_sub( context->sub_type );
    respose.set_type_m((NetWorkPackageModel) context->mod_type );
    respose.set_code( 200 );
    respose.set_body( data, len );
    context->con->send( respose.SerializeAsString());
    return 0;
}

int BaseBusiness::call200(int mod_type, int sub_type, int taskid, const TcpConnPtr &con, std::string &body)
{
    NetWorkPackageRespose respose;
    respose.set_taskid( taskid );
    respose.set_type_sub( sub_type );
    respose.set_type_m((NetWorkPackageModel) mod_type );
    respose.set_code( 200 );
    respose.set_body( body );
    con->send( respose.SerializeAsString());
    return 0;
}

int BaseBusiness::call500(EventContext *context, std::string errorMsgData)
{
    NetWorkPackageRespose respose;
    ErrorMessage errorMessage;
    errorMessage.set_errmsg( errorMsgData );
    respose.set_taskid( context->taskid );
    respose.set_type_sub( context->sub_type );
    respose.set_type_m((NetWorkPackageModel) context->mod_type );
    respose.set_code( 500 );
    respose.set_body( errorMessage.SerializeAsString());
    context->con->send( respose.SerializeAsString());
    return 0;
}

int BaseBusiness::call401(EventContext *context)
{
    NetWorkPackageRespose respose;
    respose.set_taskid( context->taskid );
    respose.set_type_sub( context->sub_type );
    respose.set_type_m((NetWorkPackageModel) context->mod_type );
    respose.set_code( 401 );
    respose.set_body( "unKnow" );
    context->con->send( respose.SerializeAsString());
    return 0;
}
